import * as types from '../constants/ActionTypes';
import Request from '../utils/request';

const fetchModifyName =
(username, sexs, intro, utype, uid, workbeginday, email, password, password2, cb) =>
 (dispatch) => {
   let sex = '';
   if (sexs === 1) {
     sex = '男';
   } else {
     sex = '女';
   }
   Request.post({
     url: '/dealer/staff',
     data: {
       username,
       sex,
       intro,
       utype,
       uid,
       workbeginday,
       email,
       password,
       password2,
       from: 'dealerstaffconfig',
     },
     success: (data) => {
       const keys = data && Object.keys(data);
       if (keys.length) {
         dispatch(checkSuccess(false, '修改姓名失败'));
         return;
       }
       if (cb) {
         cb({
           result: 1,
         });
       }
       dispatch(checkSuccess(true, ''));
     },
     fail: () => {
       if (cb) {
         cb({
           result: 0,
         });
       }
     },
     error: () => {
       if (cb) {
         cb({
           result: 0,
         });
       }
     },
   });
 };

const checkSuccess = (isSuccess, errMsg) => ({
  type: types.MODIFY_PERSON_MSG,
  isSuccess,
  errMsg,
});

export default fetchModifyName;
